<template>
    <div>
        <div class="itembox">
            <el-table :data="filteredComments" style="width: 100%;margin-top: 10px;">
                    <el-table-column property="commentContent" label="评论内容" width="500"
                        style="word-wrap: break-word;"/>
                    <el-table-column label="评论时间" width="300" property="commentTime" />
                    <el-table-column label="操作">
                        <template #default="scope">
                            <el-button type="success" size="medium" @click="handleComment(scope.$index, scope.row)">
                                审核通过
                            </el-button>
                        </template>
                    </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
import req from '@/utils/request';

export default {
    components: {

    },
    data() {
        return {
            feedback: [],
            comments: [],
        }
    },
    computed: {
        filteredComments() {
            // 过滤出isCheck为0的评论
            return this.comments.filter(comment => comment.isCheck === 0);
        }
    },
    watch: {

    },
    mounted() {
        // req.get("/cuisineFeedback/list").then(res => {
        //     this.feedback = this.feedback.concat(res.data);
        //     // console.log(res.data);

        //     console.log(this.feedback);
        //     req.get("/attractionFeedback/list").then(res2 => {
        //         this.feedback = this.feedback.concat(res2.data);

        //         // this.feedback  += res.data;
        //     })
        // })
        req.get("/attractionComments/list").then(res => {
            this.comments = this.comments.concat(res.data)
            // console.log(this.comments); 
            req.get("/cuisineComments/list").then(res2 => {
                this.comments = this.comments.concat(res2.data);
                // console.log(this.comments);
            })
        })

    },
    methods: {
        handleComment(index, row) {
            var id = row.commentsId;
            if (Object.keys(row)[2]==="attractionId") {
                req.put("/attractionComments/isCheck/" + id).then(res => {
                    this.$emit("handleLoading")
                })
            }
            if (Object.keys(row)[2]==="cuisineId") {
                req.put("/cuisineComments/isCheck/" + id).then(res => {
                    this.$emit("handleLoading")
                })
            }

        },
        // 2秒加载
        handleLoading() {
            this.loading = true;
            setTimeout(() => {
                this.loading = false;
                location.reload();
            }, 1000);
        },
    }
};
</script>
<style scoped>
.itembox {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
}
</style>